class DateUtil {
  // 格式化日期
  format(date: Date, fmtStr: string = 'YY-MM-DD hh:mm:ss') {
    let ret
    let o: any = {
      "Y+": (date.getFullYear()).toString(),
      "M+": (date.getMonth() + 1).toString(),
      "D+": (date.getDate()).toString(),
      "h+": (date.getHours()).toString(),
      "m+": (date.getMinutes()).toString(),
      "s+": (date.getSeconds()).toString(),
      "q+": (Math.floor((date.getMonth()+3)/3)).toString(),
      "S":  (date.getMilliseconds()).toString(),
    } 
    for (let k in o) {
        ret = new RegExp("(" + k + ")").exec(fmtStr);
        if (ret) {
          fmtStr = fmtStr.replace(ret[1], (ret[1] && o[k].length == 1) ? '0'+o[k] : o[k] )
        }
    }
    return fmtStr
  }


  // 时间戳格式化日期
  formatTimeStamp(timeStamp: number, fmt: string): string {
    let date = new Date(timeStamp);
    return this.format(date, fmt);
  }


}

export default new DateUtil()